package Leetcode;



public class maxProfitI {
    public int maxProfit(int[] prices) {
        if(prices.length<2)
            return 0;
        int sum=0;
        int buy=prices[0];

        for (int i=1;i<prices.length;i++){
            if(prices[i]>buy){
                sum=Math.max(sum,prices[i]-buy);
            }else {
                buy=prices[i];
            }
        }
      return sum;
    }

    public static void main(String[] args) {
        int[] a={2,3,7};
        maxProfitI maxProfit=new maxProfitI();
        System.out.println(maxProfit.maxProfit(a));

    }
}
